import { JSXProps } from '@knno/dom/jsx';
import { FileItem, Files as UIFiles, files, FilesType } from '../components/files/files';
import { AttrCheck, isArray, isBool, isNumber, isStr, jsxBuild } from './utils';
import { Nodes } from '@knno/dom';

export { UIFiles };

interface FilesProps extends JSXProps<UIFiles> {
	readonly?: boolean;
	reorder?: boolean;
	disabled?: boolean;
	value?: FileItem[];
	type?: FilesType;
	max?: number;
}

const FILES_ATTRS: AttrCheck = {
	readonly: isBool,
	reorder: isBool,
	disabled: isBool,
	value: isArray,
	type: isStr,
	max: isNumber,
};

export function Files(props: FilesProps, children: Nodes[]): UIFiles {
	return jsxBuild(files(), props, children, FILES_ATTRS);
}
